<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">












  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.2.0">


  <link rel="mask-icon" href="/images/logo.svg?v=7.2.0" color="#222">






<link rel="stylesheet" href="/css/main.css?v=7.2.0">






<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">






  
  
  <link rel="stylesheet" href="/lib/fancybox/source/jquery.fancybox.css">



<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.2.0',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":true},
    copycode: {"enable":true,"show_result":true,"style":null},
    fancybox: true,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    search: {
      root: '/',
      path: 'search.xml'
    },
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    }
  };
</script>

  <meta name="description" content="什么是ElectronElectron 是前端开发者去构建跨平台桌面应用的一种方案。大家熟悉的 Atom 和 VSCode 编辑器就是使用 Electron 开发的。 Electron 是 Node.js 和 Chromium 浏览器的结合体，用 Chromium 浏览器显示出的 Web 页面作为应用的 GUI，通过 Node.js 去和操作系统交互。 当你在 Electr">
<meta name="keywords" content="electron,前端">
<meta property="og:type" content="article">
<meta property="og:title" content="Electron 应用 （爱翻译）">
<meta property="og:url" content="https://blog.youngzk.com/posts/e39f5ecb/index.html">
<meta property="og:site_name" content="Muniz Blog">
<meta property="og:description" content="什么是ElectronElectron 是前端开发者去构建跨平台桌面应用的一种方案。大家熟悉的 Atom 和 VSCode 编辑器就是使用 Electron 开发的。 Electron 是 Node.js 和 Chromium 浏览器的结合体，用 Chromium 浏览器显示出的 Web 页面作为应用的 GUI，通过 Node.js 去和操作系统交互。 当你在 Electr">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-07-28T12:06:43.101Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Electron 应用 （爱翻译）">
<meta name="twitter:description" content="什么是ElectronElectron 是前端开发者去构建跨平台桌面应用的一种方案。大家熟悉的 Atom 和 VSCode 编辑器就是使用 Electron 开发的。 Electron 是 Node.js 和 Chromium 浏览器的结合体，用 Chromium 浏览器显示出的 Web 页面作为应用的 GUI，通过 Node.js 去和操作系统交互。 当你在 Electr">





  
  
  <link rel="canonical" href="https://blog.youngzk.com/posts/e39f5ecb/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  
  <title>Electron 应用 （爱翻译） | Muniz Blog</title>
  






  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?502753d7b083822cd84ffc61132a5ac4";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>







  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="stylesheet" href="/assets/css/APlayer.min.css" class="aplayer-style-marker">
<script src="/assets/js/APlayer.min.js" class="aplayer-script-marker"></script>
<script src="/assets/js/Meting.min.js" class="meting-script-marker"></script>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Muniz Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-books">

    
    
      
    

    

    <a href="/books" rel="section"><i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br>阅读</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          <a href="javascript:;" class="popup-trigger">
          
            <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
      

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://blog.youngzk.com/posts/e39f5ecb/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="修心">
      <meta itemprop="description" content="修不被别人影响的心，修不被自己控制的心，修不被别人诱惑的心。">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Muniz Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Electron 应用 （爱翻译）

              
            
          </h1>
        

        <div class="post-meta">

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-08-14 21:24:55" itemprop="dateCreated datePublished" datetime="2018-08-14T21:24:55+08:00">2018-08-14</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-07-28 20:06:43" itemprop="dateModified" datetime="2019-07-28T20:06:43+08:00">2019-07-28</time>
              </span>
            
          

          

          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
                 阅读次数： 
                <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
              </span>
            </span>
          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <!-- 简单示例 (id, server, type) song, playlist, album, search, artist -->

    <div id="aplayer-LhXSKZVT" class="aplayer aplayer-tag-marker meting-tag-marker" data-id="1380262830" data-server="netease" data-type="song" data-mode="circulation" data-autoplay="false" data-mutex="true" data-listmaxheight="340px" data-preload="auto" data-theme="#ad7a86"></div>





<h3 id="什么是Electron"><a href="#什么是Electron" class="headerlink" title="什么是Electron"></a>什么是Electron</h3><p><a href="https://link.juejin.im?target=https%3A%2F%2Felectron.atom.io" target="_blank" rel="noopener">Electron</a> 是前端开发者去构建跨平台桌面应用的一种方案。大家熟悉的 Atom 和 VSCode 编辑器就是使用 Electron 开发的。</p>
<p><a href="https://link.juejin.im?target=https%3A%2F%2Felectron.atom.io" target="_blank" rel="noopener">Electron</a> 是 Node.js 和 Chromium 浏览器的结合体，用 Chromium 浏览器显示出的 Web 页面作为应用的 GUI，通过 Node.js 去和操作系统交互。 当你在 Electron 应用中的一个窗口操作时，实际上是在操作一个网页。当你的操作需要通过操作系统去完成时，网页会通过 Node.js 去和操作系统交互。</p>
<a id="more"></a>

<p><a href="https://link.juejin.im?target=https%3A%2F%2Felectron.atom.io" target="_blank" rel="noopener">Electron</a> 开发桌面端应用的优点有：</p>
<ul>
<li>降低开发门槛，减少了学习的成本，只需掌握前端技术和 Node.js 即可，不需要为开发一个桌面应用去学习其它的编程语言。</li>
<li>由于 Chromium 浏览器和 Node.js 都是跨平台的，Electron 能做到写一份代码在不同的操作系统运行。</li>
<li>而且可以使用vue\react等框架去开发GUI，总之强大的生态系统还需要灵活的统筹能力，去组合。</li>
</ul>
<h3 id="Electron的进程问题？"><a href="#Electron的进程问题？" class="headerlink" title="Electron的进程问题？"></a>Electron的进程问题？</h3><h4 id="1、-主进程-Main-Process"><a href="#1、-主进程-Main-Process" class="headerlink" title="1、 主进程 Main Process"></a>1、 主进程 Main Process</h4><p>主进程，其实就是electron执行时，首次加载的可执行代码资源。我要渲染每个GUI页面，就需要有主进程去把控资源的分配、释放。那么在Electron中怎么确认我写的那个文件是主进程文件呢。<br>主进程加载的文件就是：packages.json 文件中的main字段指向的文件。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">这是一份最基础的主进程代码</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> &#123; app, BrowserWindow &#125; = <span class="built_in">require</span>(<span class="string">'electron'</span>)</span><br><span class="line"><span class="keyword">let</span> win</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createWindow</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  win = <span class="keyword">new</span> BrowserWindow(&#123; <span class="attr">width</span>: <span class="number">800</span>, <span class="attr">height</span>: <span class="number">600</span> &#125;)</span><br><span class="line">  <span class="keyword">const</span> indexPageURL = <span class="string">`file://<span class="subst">$&#123;__dirname&#125;</span>/dist/index.html`</span>;</span><br><span class="line">  win.loadURL(indexPageURL);</span><br><span class="line">  win.on(<span class="string">'closed'</span>, () =&gt; &#123;</span><br><span class="line">    win = <span class="literal">null</span></span><br><span class="line">  &#125;)</span><br><span class="line">&#125;</span><br><span class="line">app.on(<span class="string">'ready'</span>, createWindow)</span><br><span class="line">app.on(<span class="string">'window-all-closed'</span>, () =&gt; &#123;</span><br><span class="line">  <span class="keyword">if</span> (process.platform !== <span class="string">'darwin'</span>) &#123;</span><br><span class="line">    app.quit()</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<h4 id="2、渲染进程Render-Process"><a href="#2、渲染进程Render-Process" class="headerlink" title="2、渲染进程Render Process"></a>2、渲染进程Render Process</h4><p>渲染进程，就是用来进行进行页面的渲染，在主进城创建好友，会调用渲染进程去渲染页面资源。渲染进程指向的资源也就是你构建好、要呈现视图的HTML前端代码资源文件。比如你使用webpack构建出来的dist文件夹里面的数据就是。<br>渲染进程也可以看作是浏览器的每一个页面，一个页面对应一个进程，是不相同的。渲染进程的创建需要由主进程BrowserWindow对象去创建。</p>
<h4 id="3、主进程与渲染进程的关系"><a href="#3、主进程与渲染进程的关系" class="headerlink" title="3、主进程与渲染进程的关系"></a>3、主进程与渲染进程的关系</h4><ul>
<li>主进程在创建好后，会在创建一个子进程去加载资源，资源可以是网路资源(网站地址)，也可以是本地资源(html文件)。</li>
<li>主进程在创建窗口对象后，才会通过子进程去加载资源，那么窗口创建是有相应的生命周期事件去触发的。详情见# <a href="https://electronjs.org/docs/api/browser-window#browserwindow" target="_blank" rel="noopener">BrowserWindow</a></li>
</ul>
<h4 id="4、进程通信-主进程-渲染进程"><a href="#4、进程通信-主进程-渲染进程" class="headerlink" title="4、进程通信 [主进程-渲染进程]"></a>4、进程通信 [主进程-渲染进程]</h4><p>我们在开发网页应用的时候，需要实现跨页面通信。可以使用<strong>localStorage</strong> 和 <strong>H5 postMessages</strong>。那么到了electron中同样适用，但是还有其它的方法去实现通信。就是进程通信！</p>
<ul>
<li>一种是使用<a href="https://github.com/electron/electron/blob/v1.1.3/docs/api/ipc-main.md" target="_blank" rel="noopener">ipcMain</a>和<a href="https://github.com/electron/electron/blob/v1.1.3/docs/api/ipc-renderer.md" target="_blank" rel="noopener">ipcRenderer</a>模块，在渲染进程中使用ipcRender模块向主进程发送消息，主进程中ipcMain接收消息，进行操作，如果还需要反馈，则通知渲染进程，渲染进程根据接收的内容执行相应的操作：</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">主进程</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> &#123;app, BrowserWindow, ipcMain&#125; =  <span class="built_in">require</span>(<span class="string">'electron'</span>);</span><br><span class="line"></span><br><span class="line">ipcMain.on(<span class="string">'fy'</span>, <span class="function"><span class="keyword">function</span> (<span class="params">event, value</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">const</span> &#123;net&#125; = <span class="built_in">require</span>(<span class="string">'electron'</span>)</span><br><span class="line">    <span class="keyword">const</span> request = net.request(<span class="string">'http://translate.google.cn/translate_a/single?client=gtx&amp;dt=t&amp;ie=UTF-8&amp;oe=UTF-8&amp;sl=auto&amp;tl=en&amp;q='</span> + value)</span><br><span class="line">    request.on(<span class="string">'response'</span>, (response) =&gt; &#123;</span><br><span class="line">      response.setEncoding(<span class="string">'utf8'</span>);</span><br><span class="line">      <span class="keyword">let</span> connect = <span class="string">''</span>;</span><br><span class="line">      response.on(<span class="string">'data'</span>, (chunk) =&gt; &#123;</span><br><span class="line">        connect = chunk;</span><br><span class="line">      &#125;)</span><br><span class="line">      response.on(<span class="string">'end'</span>, () =&gt; &#123;</span><br><span class="line">        mainWindow</span><br><span class="line">          .webContents</span><br><span class="line">          .send(<span class="string">'fymessage'</span>, connect)</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;)</span><br><span class="line">    request.end();</span><br><span class="line">  &#125;)</span><br><span class="line"></span><br><span class="line">渲染进程</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> &#123;remote, dialog, ipcRenderer&#125; <span class="keyword">from</span>  <span class="string">'electron'</span>;</span><br><span class="line"></span><br><span class="line">handleSearch  = <span class="function">(<span class="params">value</span>) =&gt;</span>&#123;</span><br><span class="line">    ipcRenderer.send(<span class="string">"fy"</span>,value);</span><br><span class="line">    <span class="keyword">const</span>  that  =  <span class="keyword">this</span>;</span><br><span class="line">    ipcRenderer.on(<span class="string">"fymessage"</span>, (event, text) =&gt; &#123;</span><br><span class="line">        <span class="built_in">console</span>.log(text);</span><br><span class="line">        that.setState(&#123;</span><br><span class="line">        languageText:  text.split(<span class="string">'\",'</span>)[<span class="number">0</span>].replace(<span class="regexp">/\[\[\[\"/g</span>,<span class="string">''</span>)</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>第二种是直接在渲染进程使用<a href="http://electron.atom.io/docs/api/remote/" target="_blank" rel="noopener">remote</a>模块，remote 模块可以直接获取主进程中的模块。这种方式其实是第一种方式的简化。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">通过remote对象调用主进程进行dialog操作。</span><br><span class="line"></span><br><span class="line"> remote.dialog.showErrorBox(<span class="string">"翻译失败"</span>, <span class="string">"翻译内容不能为空，请重新执行"</span>);</span><br></pre></td></tr></table></figure>



<ul>
<li>第三种是主进程向渲染进程发送消息</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mainWindow：是通过 <span class="keyword">new</span>  BrowserWindow(&#123;&#125;) 创建出来的窗口对象。</span><br><span class="line">mainWindow.webContents.send(<span class="string">'发送标识-类型判断'</span>, <span class="string">'发送内容'</span>)</span><br></pre></td></tr></table></figure>

<ul>
<li>第四种是渲染进程之间的通信</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 主进程</span></span><br><span class="line"><span class="comment">// 两个窗口互相获取对方的窗口 id, 并发送给渲染进程</span></span><br><span class="line">win1.webContents.send(<span class="string">'distributeIds'</span>,&#123;</span><br><span class="line">    win2Id : win2.id</span><br><span class="line">&#125;);</span><br><span class="line">win2.webContents.send(<span class="string">'distributeIds'</span>,&#123;</span><br><span class="line">    win1Id : win1.id</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 渲染进程</span></span><br><span class="line"><span class="comment">// 通过 id 得到窗口</span></span><br><span class="line">remote.BrowserWindow.fromId(win2Id).webContents.send(<span class="string">'someMsg'</span>, <span class="string">'someThing'</span>);</span><br></pre></td></tr></table></figure>

<p>总体来说，electron开发不是很难，而是对浏览器的重新认识。<br>在上述的列子中，讲解了如何进程通信，也表述了 electron 的 net 模块，进行http通信。在这里我使用了谷歌的翻译接口，这个接口也是逆向分析出来的。怎么分析就不叙述了。这里只概述electron的知识体系。 </p>
<p>剩下就是node的各个模块操作了。在electron中调用node的模块。如http,fs,等。</p>

      
    </div>

    
      

  <div class="popular-posts-header">相关文章推荐</div>
  <ul class="popular-posts">
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="/posts/554d6708/" rel="bookmark">Electron-cer 跨平台证书安装</a></div>
      
    </li>
  
  </ul>


    

    
      
    

    
    
    

    

    
      
    
    

    
      <div>
        




  



<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>修心</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    
    <a href="https://blog.youngzk.com/posts/e39f5ecb/" title="Electron 应用 （爱翻译）">https://blog.youngzk.com/posts/e39f5ecb/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-CN" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        
          
        
        <div class="post-tags">
          
            <a href="/tags/electron/" rel="tag"># electron</a>
          
            <a href="/tags/前端/" rel="tag"># 前端</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/posts/f8f5c654/" rel="prev" title="基于mobx的表单验证(mobx-react-form)">
                基于mobx的表单验证(mobx-react-form) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>

  </div>


          </div>
          
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">

          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  
    <a href="/">
      <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="修心">
      </a>
  
  <p class="site-author-name" itemprop="name">修心</p>
  <div class="site-description motion-element" itemprop="description">修不被别人影响的心，修不被自己控制的心，修不被别人诱惑的心。</div>
</div>


  <nav class="site-state motion-element">
    
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">17</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    

    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        
        
          
        
          
        
          
        
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    

    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">20</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>







  <div class="links-of-author motion-element">
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/1160007652" title="GitHub &rarr; https://github.com/1160007652" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="mailto:1160007652@qq.com" title="E-Mail &rarr; mailto:1160007652@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
    
  </div>



  <div class="cc-license motion-element" itemprop="license">
  
  
    
  
  
  
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-CN" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>





          
          
        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#什么是Electron"><span class="nav-number">1.</span> <span class="nav-text">什么是Electron</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Electron的进程问题？"><span class="nav-number">2.</span> <span class="nav-text">Electron的进程问题？</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、-主进程-Main-Process"><span class="nav-number">2.1.</span> <span class="nav-text">1、 主进程 Main Process</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、渲染进程Render-Process"><span class="nav-number">2.2.</span> <span class="nav-text">2、渲染进程Render Process</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3、主进程与渲染进程的关系"><span class="nav-number">2.3.</span> <span class="nav-text">3、主进程与渲染进程的关系</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4、进程通信-主进程-渲染进程"><span class="nav-number">2.4.</span> <span class="nav-text">4、进程通信 [主进程-渲染进程]</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 – <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">修心</span>

  

  
</div>

<div>
  修不被别人影响的心，修不被自己控制的心，修不被别人诱惑的心。
</div>









        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="post-meta-item-icon">
      <i class="fa fa-user"></i>
    </span>
    <span class="site-uv" title="总访客量">
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="post-meta-divider">|</span>
  

  
    <span class="post-meta-item-icon">
      <i class="fa fa-eye"></i>
    </span>
    <span class="site-pv" title="总访问量">
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

    

    

  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>






  











  
  









  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/fancybox/source/jquery.fancybox.pack.js"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>




  <script src="/js/utils.js?v=7.2.0"></script>

  <script src="/js/motion.js?v=7.2.0"></script>



  
  


  <script src="/js/affix.js?v=7.2.0"></script>

  <script src="/js/schemes/pisces.js?v=7.2.0"></script>



  
  <script src="/js/scrollspy.js?v=7.2.0"></script>
<script src="/js/post-details.js?v=7.2.0"></script>



  <script src="/js/next-boot.js?v=7.2.0"></script>

  

  

  


  













  <script src="/js/local-search.js?v=7.2.0"></script>












<script>
// GET RESPONSIVE HEIGHT PASSED FROM IFRAME

window.addEventListener("message", function(e) {
  var data = e.data;
  if ((typeof data === 'string') && (data.indexOf('ciu_embed') > -1)) {
    var featureID = data.split(':')[1];
    var height = data.split(':')[2];
    $(`iframe[data-feature=${featureID}]`).height(parseInt(height) + 30);
  }
}, false);
</script>








  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"react":{"opacity":0.7},"log":false});</script></body>
</html>
